INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SRC_DIR})
FILE(GLOB CRASHREPORT_SRC *.cpp *.rc)
FILE(GLOB CRASHREPORT_HDR *.h)

SET(CRASHREPORT_QRC resources.qrc)

SET(CRASHREPORT_MOC_HDR
crash_report_socket.h
crash_report_widget.h
)

SET(CRASHREPORT_UI
crash_report_widget.ui
)

IF(WITH_QT)
  SET(QT_USE_QTGUI TRUE)
  SET(QT_USE_QTNETWORK TRUE)
  SET(QT_USE_QTMAIN TRUE)
  SET(QT_USE_QTOPENGL FALSE)
  SET(QT_USE_QTXML FALSE)

  INCLUDE_DIRECTORIES(${QT_INCLUDES})
  INCLUDE(${QT_USE_FILE})
  ADD_DEFINITIONS(${QT_DEFINITIONS})

  QT4_ADD_RESOURCES(CRASHREPORT_QRC_SRCS ${CRASHREPORT_QRC})
  QT4_WRAP_CPP(CRASHREPORT_MOC_SRC ${CRASHREPORT_MOC_HDR})
  QT4_WRAP_UI(CRASHREPORT_UI_HDR ${CRASHREPORT_UI})

  SET(QT_LIBRARIES ${QT_LIBRARIES} ${QT_QTMAIN_LIBRARY})
ELSE()
  QT5_ADD_RESOURCES(CRASHREPORT_QRC_SRCS ${CRASHREPORT_QRC})
  QT5_WRAP_CPP(CRASHREPORT_MOC_SRC ${CRASHREPORT_MOC_HDR})
  QT5_WRAP_UI(CRASHREPORT_UI_HDR ${CRASHREPORT_UI})
ENDIF()

SOURCE_GROUP(QtResources FILES ${CRASHREPORT_UI} ${CRASHREPORT_QRC_SRCS})
SOURCE_GROUP(QtGeneratedUiHdr FILES ${CRASHREPORT_UI_HDR})
SOURCE_GROUP(QtGeneratedMocSrc FILES ${CRASHREPORT_MOC_SRC})
SOURCE_GROUP("source files" FILES ${CRASHREPORT_SRC})
SOURCE_GROUP("header files" FILES ${CRASHREPORT_HDR})

ADD_EXECUTABLE(crash_report WIN32 ${CRASHREPORT_SRC} ${CRASHREPORT_HDR} ${CRASHREPORT_MOC_SRC} ${CRASHREPORT_UI_HDR} ${CRASHREPORT_QRC_SRCS})
TARGET_LINK_LIBRARIES(crash_report ${QT_LIBRARIES})

NL_DEFAULT_PROPS(crash_report "NeL, Tools, Misc: Crash Report")
NL_ADD_RUNTIME_FLAGS(crash_report)

INSTALL(TARGETS crash_report RUNTIME DESTINATION ${NL_BIN_PREFIX})
